<template>
  <div id="app" class="wrapper wrapper-content animated fadeInRight v-cloak" v-cloak>
    <div class="row">
      <div class="ibox float-e-margins">
        <div class="ibox-content col-md-12">
          <form id="reportTaskForm" method="post" class="form m-t" accept-charset="UTF-8">
            <input type="hidden" name="id" v-model="item.id"/>
            <input type="hidden" id="bean-auditState" name="auditState" value="0"/>
            <div class="clearfix "></div>
            <div class="col-md-12">
              <div class="form-group clearfix">
                <label class="col-md-8 control-label">报送信息</label>
              </div>
            </div>
            <div class="col-md-12">
              <div class="col-md-6">
                <div class="form-group clearfix">
                  <label class="col-md-8 control-label">报送标题：</label>
                  <div class="col-md-12 ">
                    <div class="form-control">{{item.title}}</div>
                  </div>
                </div>

                <div class="form-group clearfix">
                  <label class="col-md-8 control-label">报送人：</label>
                  <div class="col-md-12 ">
                    <div class="form-control">{{item.reportingRiveruserName}}</div>
                  </div>
                </div>
                <div class="form-group clearfix">
                  <label class="col-md-8 control-label">提交日期：</label>
                  <div class="col-md-12 ">
                    <div class="form-control">{{item.reportingDate}}</div>
                  </div>
                </div>
              </div>
              <div class="col-md-12">
                <div class="form-group clearfix">
                  <label class="col-md-8 control-label">填报内容：</label>
                  <div class="col-md-12 ">
                    <div class="form-control" v-html="item.reportingContent"></div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-md-12">
              <div class="form-group clearfix">
                <label class="col-md-8 control-label">报送信息</label>
              </div>
            </div>
            <div class="col-md-12">
              <div class="col-md-6">
                <div class="form-group clearfix">
                  <label class="col-md-8 control-label">经办人：</label>
                  <div class="col-md-12">
                    <input autocomplete="off" id="bean-auditOperatorName" name="auditOperatorName" v-model="item.auditOperatorName" class="laydate-icon form-control layer-date" type="text" placeholder="请输入经办人" required="" aria-required="true" aria-describedby="bean-auditOperatorName-error" aria-invalid="true">
                    <span id="bean-auditOperatorName-error" class="help-block m-b-none" for="bean-auditOperatorName"></span>
                  </div>
                </div>
              </div>
              <div class="col-md-12">
                <div class="form-group clearfix">
                  <label class="col-md-8 control-label">打回原因：</label>
                  <div class="col-md-12">
                    <textarea id="bean-auditResult" name="auditResult" class="form-control" placeholder="请输入打回原因" aria-required="true" aria-describedby="bean-auditResult-error" maxlength="1255" aria-invalid="true">{{item.auditResult}}</textarea>
                    <span id="bean-auditResult-error" class="help-block m-b-none" for="bean-auditResult"></span>
                  </div>
                </div>
              </div>
            </div>

            <div class="clearfix "></div>
            <div class="col-12 text-center" style="height: 50px;">
              <div>
                <input class="btn btn-primary" type="button" @click="audit(1)" value="审核通过"/> | <input class="btn btn-danger" type="button" @click="audit(2)" value="打回重报"/>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
  import '@/assets/css/style.css'

  import $ from '@/assets/js/jquery-vendor.js'
  import 'jquery.cookie'
  import axios from 'axios'
  import '@/assets/js/validate/validation-vendor.js'
  import {apiUtil, axiosContentType, site} from '@/assets/js/boss'

  export default {
    data() {
      return {
        item: {}
      }
    },
    mounted() {
      let that = window.$vueApp = this;
      document.getElementsByTagName('body')[0].className = 'fixed-sidebar full-height-layout';
      $('#reportTaskForm').validate();
      that.staff.init(function () {
        if (apiUtil.existSessionKey(site.reportTask.itemAudit)) {
          that.info();
        }
      });
    },
    methods: {
      info() {
        let that = this;
        axios.get(site.reportTaskSubmit.info + sessionStorage.getItem(site.reportTask.itemAudit), {}).then(function (response) {
          const result = response.data;
          if (result.code === 0) {
            that.item = result.data;
          } else {
            alert(result.message);
          }
        });
      },
      audit(auditState) {
        $('#bean-auditState').val(auditState);
        let that = this;
        if ($('#reportTaskForm').valid()) {
          let auditResult = $('#bean-auditResult').val();
          if (auditState === 2 && !apiUtil.notEmpty(auditResult)) {
            alert('打回原因必填!');
            return;
          }
          console.info(site.reportTask.itemAudit)
          axios.post(site.reportTask.itemAudit, $('#reportTaskForm').serialize(),
            axiosContentType.xWwwFormUrlencoded).then(function (response) {
            const result = response.data;
            // console.info("获取数据.." + JSON.stringify(result));
            if (result.code === 0) {
              parent.$vueApp.page();
              alert('操作成功!');
              that.lbox.closeMyBoxLayer()
            } else {
              alert(result.message);
            }
          });
        }
      }
    }
  }
</script>

